﻿using BaseUi.ViewModel;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi
{
    /// <summary>
    /// 主页
    /// </summary>
    public partial class HomeView : UserControlBase
    {
        HomeViewModel viewModel = new HomeViewModel();

        public HomeView()
        {
            InitializeComponent();

            this.DataContext = viewModel;
            viewModel.test1List = test1.channelModels;
        }

        private void loadFir(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;

            viewModel.LoadTask();
            //viewModel.focusInput = new Action(() => {
            //    Dispatcher.Invoke(new Action(() =>
            //    {
            //        TextBoxInput.IsEnabled = true;
            //        TextBoxInput.Focus();
            //        TextBoxInput.SelectAll();
            //    }));
            //});
            //viewModel.focusInput.Invoke();
        }

        private void RunStateButClick(object sender, RoutedEventArgs e)
        {
            viewModel.RunStateClick((RunStateButtonClick)e.OriginalSource);
        }

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                viewModel.Start();
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            InitView(TextBoxMoCode.Text);

            //viewModel.mocode = TextBoxMoCode.Text;
        }

        private void InitView(string text)
        {
            OutputStatChartView.viewModel.UpdataData(text.Trim());
        }
    }
}
